<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>添加优惠券</title>
    <script type="text/javascript">
    function beforSubmit(){
    ramCardNum = document.getElementById("ramCardNum").value;
    totalNum = '${resultMap["totalNum"]}';
    if(ramCardNum > totalNum){
    alertMsg.error('符合条件的记录数为：${resultMap["totalNum"]}，随机会员卡数必须小于等于总记录数');
    return false;
    }
    if(document.getElementById("releaseType").options[document.getElementById("releaseType").selectedIndex].value == -1){
    alertMsg.error('请选择发放方式！');
    return false;
    }
   if(document.getElementById("favourableEntityName").value == ""){
      alertMsg.error('请选择优惠券！');
    return false;
    }
    return true;
    }
    
    function changeReleaseType(myInput){
     if(myInput.options[myInput.selectedIndex].value == 'ram'){
     $("#ramCardNumDiv").show();
     }else{
     $("#ramCardNumDiv").hide();
     $("#ramCardNum").attr("value","");
     }
    }
    
    function checkKeys(){
    if('${resultMap["keys"]}' == ''){
    $("select#releaseType > option")[1].disabled="disabled";
    }else{
    $("select#releaseType > option")[2].disabled="disabled";
    $("select#releaseType > option")[3].disabled="disabled";
    }
    }
    
    $(function(){checkKeys();});
    </script>
  </head>
  <body>
	<div class="pageContent">
		<form method="post" action="<%=path %>/favourable/releaseFavourable.action" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone);">
			<div class="pageFormContent" layoutH="56">&nbsp;  
				<input name="favourableVO.id" type="hidden" value="<s:property value="favourableVO.id" />" />

					<p>
					<label>发送方式：</label>
					<s:select name="releaseType"
							list="%{#{-1:'请选择','sel':'定向发送','all':'全部发送','ram':'随机发送'}}" listKey="key" listValue="value" onchange="changeReleaseType(this);" ></s:select>
					</p>
					<p>
					<label>优惠券：</label>
					<input type="hidden" name="favourable.favourableEntityId" value=""/> 
					<input name="favourable.favourableEntityName" type="text" size="30" value="" readonly="readonly" id="favourableEntityName"/>
					<a class="btnLook" href='<%=path %>/favourableEntity/listFavourableEntity.action?searchType=favourable&customerId=${resultMap["customerId"]}' lookupGroup="favourable"  >选择</a>
				    </p>
				    <p>
				    <label>发送优惠券张数</label>
				    <input type="text" name="releaseNum" size="5" class="digits required" />
				    </p>
				    <div id="ramCardNumDiv" style="display:none">
				    <p>
				    <label>随机会员卡张数</label>
				   	<input type="text" class="digits" id="ramCardNum" size="3" value="" name="ramCardNum"/>
				   	</p>
				   	</div>
				    <c:forEach items="${resultMap}" var="record">
					<input type="hidden" value="${record.value }" name="${record.key }" />  
					</c:forEach>
				    
			</div>
			<div class="formBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="submit" onclick="return beforSubmit()">发放</button></div></div></li>
					<li>
						<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
						
					</li>
				</ul>
			</div>
		</form>
	</div>
  </body>
</html>